//
//  ViewController.m
//  TCRouteDemo
//
//  Created by lincy on 2018/1/8.
//  Copyright © 2018年 lincy. All rights reserved.
//

#import "ViewController.h"
#import "CYRouter.h"



@interface ViewController () <UITableViewDelegate,UITableViewDataSource>
@property (nonatomic, strong) NSArray *urlStrs;
@property (nonatomic, strong) NSArray *routeFormats;
@property (nonatomic, strong) UITableView *tableView;
@end

@implementation ViewController
- (void)viewDidLoad {
    [super viewDidLoad];

    
    
    _routeFormats = @[
                      @"talicai:{abc}/123",
                 @"user://{userId你好}",
                      @"user://{userId你好}",
                      @"user://{userId—}",
                      @"user://{userId_}",
                      @"user://{userId8}",
                      @"user://{1238}",
                      @"user://{asd8}",
                      @"user://{asd_8}",
                      @"user://{_asd}",
                      @"user://{2_asd}",
                      @"user://{时间}",
                      @"htt{p}://{asd}/asd.{sss}1.213/{pid}/{cd}s",
                 @"myapp://post/{postId}",
                 @"user://profile",
                 @"user://2000/profile",
                 @"user://profile/3000",
                 @"user://profile/haha",
                 @"http://www.talicai.com/post/1023",
                 @"http://test.talicai.com/post/1023",
                 ];
    
    [self.view addSubview:self.tableView];
}

#pragma mark - TableView Datasource & Delegate
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.routeFormats.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
    cell.textLabel.text = self.routeFormats[indexPath.row];
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 40;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    NSString *format = self.routeFormats[indexPath.row];
//    CYRouteResponse *response = [[CYRouter share]prase:urlStr];
//    if (response.handler) {
//        response.handler(response.params);
//    }
    
    
    [[CYRouter share] addRoute:format paramRegexs:nil handler:^(NSDictionary *params) {
        //            NSLog(@"route to '%@'",urlStr);
    }];
}


- (UITableView *)tableView {
    if (_tableView == nil) {
        _tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 64, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height) style:UITableViewStyleGrouped];
        _tableView.delegate = self;
        _tableView.dataSource = self;
        [_tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"cell"];
    }
    return _tableView;
}

@end
